//用于删除邮件的servlet
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javax.mail.*;

public class DoDelete extends HttpServlet {

	public DoDelete() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session=request.getSession();
		int msgnum = Integer.parseInt(request.getParameter("msgnum"));
		Folder folder=(Folder) session.getAttribute("folder");
		
		String username="";
		String password="";
		username=request.getParameter("username");
		password=request.getParameter("password");
		System.out.println("username"+username);
		try {
			Message msg = folder.getMessage(msgnum);
			msg.setFlag(Flags.Flag.DELETED, true);
			folder.close(true);
			folder.open(Folder.READ_WRITE);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		response.sendRedirect("/Mail/mailbox.jsp?username="+username+"&password="+password);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
